package structural.composite;

import java.util.ArrayList;
import java.util.List;

public class CourseCatalog extends CatalogComponenet {
    private List<CatalogComponenet> list = new ArrayList<CatalogComponenet>();
    private String name;
    private String price;
    private Integer level;
    public CourseCatalog(String name,Integer level){
        this.name = name;
        this.level = level;
    }

    @Override
    public void add(CatalogComponenet catalogComponenet) {
        list.add(catalogComponenet);
    }

    @Override
    public void remove(CatalogComponenet catalogComponenet) {
        list.remove(catalogComponenet);
    }

    @Override
    public void print() {
        System.out.println(this.name);
        list.stream().forEach(
                i->{
                    if(level!=null){
                        for(int j=0;j<level;j++){
                            System.out.print("  ");
                        }
                    }
                    i.print();
                }
        );

    }
}
